{extend name="layout/default" /}
{block name="title"}资料修改{/block}
{block name="content"}
<form class="layui-form" action="">
    <div class="mainBox" style="background-color: white;">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input" value="{$user.username}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">旧密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="old_password" placeholder="请输入当前密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">新密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" placeholder="留空则不修改" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="form-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script>
    layui.use(['form','jquery', 'popup'],function(){
        let form = layui.form;
        let $ = layui.jquery;
        let popup = layui.popup;
        let MODULE_PATH = "/{:request()->controller()}";

        form.on('submit(form-save)', function(data){
            let loading = layer.load();
            $.ajax({
                url: MODULE_PATH + "/profile",
                data: data.field,
                dataType:'json',
                type:'post',
                success:function(res){
                    layer.close(loading);
                    if(Number(res.code) === 0){
                        popup.success(res.msg, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("dataTable");
                        });
                    }else{
                        layer.close(loading);
                        popup.failure(res.msg);
                    }
                },
                error: function (res) {
                    layer.close(loading);
                    popup.failure("网络错误, 请重试");
                }
            })
            return false;
        });

        let tp_debug = $("#think_page_trace_open");
        (tp_debug.length > 0) && tp_debug.remove();
    })
</script>
{/block}